package rabbitmq.component;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


/**
 * 接收mq消息
 */
@Component

public class RabbitReceiver11 {
    public Logger log = LoggerFactory.getLogger(this.getClass());

    @RabbitListener(queues = "hello")
    public void helloQueue(Message message) {
        log.info("helloQueue接收消息  : " + new String(message.getBody()));
    }

    @RabbitListener(bindings=@QueueBinding(value=@Queue(value="fanout",durable = "true",autoDelete="false"),
                    exchange=@Exchange(value="fanout.exchange",durable = "true",type= ExchangeTypes.FANOUT)))
    public void fanoutExchange(Message message) {
        log.info("fanout接收消息  : " + new String(message.getBody()));
    }


    @RabbitListener(bindings=@QueueBinding(value=@Queue(value="direct",durable = "true",autoDelete="false"),
                    exchange=@Exchange(value="direct.exchange",durable = "true",type=ExchangeTypes.DIRECT), key="routingKey.direct"))
    public void directExchange(Message message) {
        log.info("direct接收消息  : " + new String(message.getBody()));
    }
}
